package com.ht.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.modules.system.entity.*;
import com.ht.modules.system.mapper.ActCandidateConfigMapper;
import com.ht.modules.system.service.IActCandidateConfigService;
import com.ht.utils.DicConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批流候选人配置
 */
@Service
public class ActCandidateConfigServiceImpl extends ServiceImpl<ActCandidateConfigMapper, ActCandidateConfig> implements IActCandidateConfigService {

    @Autowired
    private ActCandidateConfigMapper actCandidateConfigMapper;

    /**
     * 重写的list列表方法
     */
    @Override
    public Page<ActCandidateConfigVo> list(Page<ActCandidateConfigVo> page, ActCandidateConfigVo actCandidateConfigVo, String column, String order) {
        return page.setRecords(actCandidateConfigMapper.list(page, actCandidateConfigVo, column, order));
    }

    /**
     * 新增方法
     */
    @Override
    public void add(ActCandidateConfig actCandidateConfig) {
        actCandidateConfig.setDelFlag(DicConstants.DEL_FLAG_WSC);
        this.save(actCandidateConfig);
    }

    /**
     * 编辑方法
     */
    @Override
    public void edit(ActCandidateConfig actCandidateConfig) {
        ActCandidateConfig actCandidateConfigEntity = this.getById(actCandidateConfig.getId());
        if (actCandidateConfigEntity == null) {
            throw new RuntimeException("未找到对应实体！");
        }
        this.updateById(actCandidateConfig);
    }

    /**
     * 删除方法（逻辑删除）
     */
    @Override
    public void delete(String id) {
        ActCandidateConfig actCandidateConfig = this.getById(id);
        if (actCandidateConfig == null) {
            throw new RuntimeException("未找到对应实体！");
        }
        actCandidateConfig.setDelFlag(DicConstants.DEL_FLAG_YSC);
        this.updateById(actCandidateConfig);
    }

    /**
     * 批量删除方法（逻辑删除）
     */
    @Override
    public void deleteBatch(String ids) {
        if (ids == null || ids.trim().isEmpty()) {
            throw new RuntimeException("参数不识别！");
        }
        actCandidateConfigMapper.updateBatchByIds("del_flag", DicConstants.DEL_FLAG_YSC, ids.split(","));
    }

    /**
     * 通过id查询方法
     */
    @Override
    public ActCandidateConfig queryById(String id) {
        ActCandidateConfig actCandidateConfig = this.getById(id);
        if (actCandidateConfig == null) {
            throw new RuntimeException("未找到对应实体！");
        }
        return actCandidateConfig;
    }

    @Override
    public List<ActCandidateTable> queryTableName(String tableName) {
        return actCandidateConfigMapper.queryTableName(tableName);
    }

    @Override
    public List<ActCandidateColumn> queryColumnsByTableName(String tableName) {
        return actCandidateConfigMapper.queryColumnsByTableName(tableName);
    }

    @Override
    public List<ActCandidateProcessNode> queryProcessNode(String processName, String processNodeName) {
        return actCandidateConfigMapper.queryProcessNode(processName, processNodeName);
    }

}
